package com.example.product_service.service.impl;

import com.example.product_service.domain.Product;
import com.example.product_service.service.ProductService;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class ProductServiceImpl implements ProductService {

    private static final Map<Integer, Product> daoMap = new HashMap<>();

    static {
        Product p1 = new Product(1, "iphonex", 999, 10);
        Product p2 = new Product(2, "冰箱", 999, 13);
        Product p3 = new Product(3, "洗衣机", 999, 4);
        Product p4 = new Product(4, "电话", 999, 44);
        Product p5 = new Product(5, "汽车", 999, 22);
        Product p6 = new Product(6, "椅子", 999, 34);
        Product p7 = new Product(7, "空调", 999, 13);

        daoMap.put(1, p1);
        daoMap.put(2, p2);
        daoMap.put(3, p3);
        daoMap.put(4, p4);
        daoMap.put(5, p5);
        daoMap.put(6, p6);
        daoMap.put(7, p7);
    }

    @Override
    public List<Product> listProduct() {
        Collection<Product> collection = daoMap.values();
        return new ArrayList<>(collection);
    }

    @Override
    public Product findById(int id) {
        return daoMap.get(id);
    }
}
